package game;

import java.util.Random;
import sengine.Level;
import sengine.Object2D;
import sengine.Sprite;
import sengine.Texture;

/**
 *
 * @author twoodf5611
 */
public class RandomLevel extends Level {

    private final Random rnd = new Random();

    public RandomLevel() {
        makePlatform(0, 520);
    }

    public void makePlatform(int xstart, int ystart) {
        int width = (int) (rnd.nextGaussian() * 60) + 400;
        Sprite floor = new Sprite(xstart, ystart, width, 40);
        floor.setPhysType(Object2D.PhysicsType.FIXED);
        floor.setTexture(Texture.loadTexture("platform.png"));
        addSprite(floor);

        if (xstart < 2000) {
            if(rnd.nextInt(500) > 60) {
                makePlatform(xstart + width + rnd.nextInt(20), ystart + (int) (rnd.nextGaussian() * 80));
            } else {
                // Split
                int ysplit = (int) (rnd.nextGaussian() * 50)+200;
                int offset = (int) (rnd.nextGaussian() * 25);
                makePlatform(xstart + width + rnd.nextInt(20), ystart + ysplit + offset);
                makePlatform(xstart + width + rnd.nextInt(20), ystart - ysplit + offset);
            }
        }
    }
}
